package cn.zyjblogs.netty.protocoltcp;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

import java.util.UUID;

public class MyServerHandler extends SimpleChannelInboundHandler<MessageProtocol> {
    private int count=0;

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MessageProtocol msg) throws Exception {
        //接收数据，并处理
        System.out.println("\n服务端接收信息：");
        System.out.println("长度="+msg.getLen());
        System.out.println("内容="+new String(msg.getContent(),CharsetUtil.UTF_8));
        System.out.println("服务器接收消息包数量="+(++this.count));
    }
}
